<?php
include "pgsql.class.php";

$objDB = new pgsql();

$tid	= $_REQUEST['tid'];

$SQL = "SELECT a.tid, a.uid, a.tracetype, a.hidecnt, a.title, a.rdate, b.path FROM trace as a LEFT JOIN tracefile as b ON (a.tid = b.tid) WHERE a.tid = " . $tid;
if($objDB->query($SQL)) {
	$res	= $objDB->fetch();
	$tmpCnt = count($res);
	$json = "{\"data\" : ";
	for($i=0;$i<$tmpCnt;$i++) {
		if($i == 0) {
			$tmpArray[$res[$i]['tid']] = $res[$i];
			$tmpArray2[$res[$i]['tid']]['path'][] = $res[$i]['path'];
		}
		if($res[$i]['tid'] != $res[$i-1]['tid'] && $i != 0) {
			$tmpArray[$res[$i]['tid']] = $res[$i];
			$tmpArray2[$res[$i]['tid']]['path'][] = $res[$i]['path'];
		} else if ($res[$i]['tid'] == $res[$i-1]['tid'] && $i != 0){
			$tmpArray2[$res[$i]['tid']]['path'][] = $res[$i]['path'];
		}
	}
	foreach($tmpArray as $key=>$value) {
		foreach($value as $keys=>$values) {
			if($keys == 'path') {
				$tmpArray[$key][$keys] = $tmpArray2[$key][$keys];
			}
		}
		//$tmpArray[$key][$value]
	}
	$objJson = new json();
	$rtn = "{\"data\" : " . $objJson->encode($tmpArray) . "}";
	print_r($rtn);
} else {
	echo "{\"error\" : 0}";
}
?>